package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.AccountUserProvider;
import com.jinmdz.fmis.dao.admin.model.accountuser.AccountUserEditItem;
import com.jinmdz.fmis.dao.admin.model.accountuser.AccountUserListData;
import com.jinmdz.fmis.dao.admin.model.accountuser.AccountUserListItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 员工账号维护Dao
 *
 * @author LiCongLu
 * @date 2020-03-17 09:35
 */
public interface AccountUserDao {

    /**
     * 查询员工账号列表
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-03-17 09:35
     */
    @SelectProvider(type = AccountUserProvider.class, method = "listAccountUserList")
    ArrayList<AccountUserListItem> listAccountUserList(@Param("data") AccountUserListData data);

    /**
     * 按照主键获取员工账号信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-17 09:35
     */
    @Select(" select id,login_username,job_no,full_name,user_gender_code" +
            " ,mobile_phone,other_phone,address,company_id,department_id,disable_state" +
            " ,as_login,ic_card_code,sort,remark,version " +
            " from system_user where id = #{id} and deleted = 0 limit 1 ")
    AccountUserEditItem getAccountUserEditById(@Param("id") Integer id);

    /**
     * 按照工号查询非当前账号信息主键
     *
     * @param userId 当前账号主键
     * @param jobNo  员工编号
     * @return
     * @author LiCongLu
     * @date 2020-03-17 09:35
     */
    @Select(" select id from system_user where id != IFNULL(#{userId},0) and job_no = #{jobNo} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getAccountUserIdByJobNo(@Param("userId") Integer userId, @Param("jobNo") String jobNo);

    /**
     * 按照登录帐号查询非当前账号信息主键
     *
     * @param userId        当前账号主键
     * @param loginUsername 登录帐号
     * @return
     * @author LiCongLu
     * @date 2020-03-17 09:35
     */
    @Select(" select id from system_user where id != IFNULL(#{userId},0) and login_username = #{loginUsername} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getAccountUserIdByLoginUsername(@Param("userId") Integer userId, @Param("loginUsername") String loginUsername);

    /**
     * 按照部门主键查询所属人员
     *
     * @param departmentId 部门主键
     * @return
     * @author LiCongLu
     * @date 2020-03-25 17:00
     */
    @Select(" select id,login_username,job_no,full_name,user_gender_code" +
            " ,mobile_phone,other_phone,address,company_id,department_id,disable_state" +
            " ,as_login,ic_card_code,sort,remark,version " +
            " from system_user where department_id = #{departmentId} and disable_state = 0 and deleted = 0 ")
    ArrayList<AccountUserEditItem> listAccountUserEditByDepartmentId(@Param("departmentId") Integer departmentId);
}